﻿using System;

class Person
{
    private string firstName;
    private string lastName;
    private Genders gender;
    private DateTime birthDate;

    private const string FirstNamePropertyName = "First name";
    private const string LastNamePropertyName = "Last name";
    private const string GenderPropertyName = "Gender";
    private const string BirthDatePropertyName = "Birth date";

    public string FirstName
    {
        get
        {
            return this.firstName;
        }
        set
        {
            string oldValue = firstName;
            this.firstName = value;
            OnPropertyChanged(FirstNamePropertyName,oldValue,this.FirstName);
        }
    }
    public string LastName
    {
        get
        {
            return lastName;
        }
        set
        {
            string oldValue = this.lastName;
            this.lastName = value;
            OnPropertyChanged(LastNamePropertyName,oldValue,value);
        }
    }
    public Genders Gender
    {
        get
        {
            return gender;
        }
        set
        {
            Genders oldValue = this.gender;
            this.gender = value;
            OnPropertyChanged(GenderPropertyName,oldValue,value);
        }
    }
    public DateTime BirthDate
    {
        get
        {
            return birthDate;
        }
        set
        {
            DateTime oldValue = this.birthDate;
            this.birthDate = value;
            OnPropertyChanged(BirthDatePropertyName, oldValue, value);
        }
    }

    private void OnPropertyChanged(string propertyName,object oldValue,object newValue)
    {
        if (PropertyEventHandler != null)
        {
            PropertyChangedEventArgs arguments = new PropertyChangedEventArgs(propertyName, oldValue, newValue);
            PropertyEventHandler(this, arguments);
        }
    }
    public event PropertyChangedEventHandler PropertyEventHandler;

    public Person()
    {
        firstName = "";
        lastName = "";
        gender = Genders.Male;
        birthDate = new DateTime();
        InitializeEventHandlers();
    }

    private void InitializeEventHandlers()
    {
        PropertyEventHandler += new PropertyChangedEventHandler(Person_PropertyEventHandler);
    }

    void Person_PropertyEventHandler(object sender, PropertyChangedEventArgs arguments)
    {
        Console.WriteLine("{0} was changed from {1} to {2}.",arguments.PropertyName,arguments.OldValue,arguments.NewValue);
    }

}
